from django.db import models


def default_price():
    return 30.0


class Book(models.Model):  # 创建 book 表
    title = models.CharField(max_length=30, unique=True, verbose_name='书名')
    public = models.CharField(max_length=50, verbose_name='出版社', default="人民出版社")
    price = models.DecimalField(max_digits=7, decimal_places=2, verbose_name='定价')
    retail_price = models.DecimalField(max_digits=7, decimal_places=2, verbose_name='零售价', default=default_price)
    author = models.CharField(max_length=50, verbose_name='作者')

    def __str__(self):
        return "title:%s pub:%s price:%s" % (self.title, self.public, self.price)

    # class Meta:
    #     # 是否使用Django 提供的 syncdb 和 reset 命令完成创建和删除数据表, 就是是否用python3 manage.py migrate迁移数据库
    #     managed = True
    #     # 指定数据表的名称, 否则自动生成appname_classname作为表名
    #     db_table = 'book'


class Author(models.Model):  # 创建作者表
    name = models.CharField(max_length=30, verbose_name='姓名')
    email = models.EmailField(verbose_name='邮箱')

    # 打印对象时显示的内容，print(Author())
    def __str__(self):
        return '作者：%s' % (self.name)


class UserInfo(models.Model):  # 创建用户信息表
    username = models.CharField(max_length=24, verbose_name='用户注册')
    password = models.CharField(max_length=24, verbose_name='密码')
    choices = (
        ("M", '男性'),
        ("F", '女性'),
    )
    gender = models.CharField(max_length=2, choices=choices, default='M')
